{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "# 初期設定"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": true,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "mysql_user=\"joruri\"\n",
    "mysql_password=\"pass\"\n",
    "mysql_port=\"3306\"\n",
    "mysql_server=\"10.136.3.175\"\n",
    "mysql_connect() \n",
    "{\n",
    "  mysql -u${mysql_user} -p\"${mysql_password}\" -P ${mysql_port} -h ${mysql_server} -e \"$1\" 2> /dev/null\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "# 接続テスト"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "+------------+\n",
      "| CURDATE()  |\n",
      "+------------+\n",
      "| 2017-07-13 |\n",
      "+------------+\n"
     ]
    }
   ],
   "source": [
    "mysql_connect \"SELECT CURDATE();\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# コマンドライン\n",
    "\n",
    "* 入力キャンセル\n",
    "\n",
    "```\n",
    "mysql> ls -ltrh\n",
    "    -> quit\n",
    "    -> \\c\n",
    "mysql>\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "# 設定確認"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "ストレージエンジンの確認"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+\n",
      "| Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |\n",
      "+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+\n",
      "| FEDERATED          | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |\n",
      "| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                          | NO           | NO   | NO         |\n",
      "| MyISAM             | YES     | MyISAM storage engine                                          | NO           | NO   | NO         |\n",
      "| BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears) | NO           | NO   | NO         |\n",
      "| CSV                | YES     | CSV storage engine                                             | NO           | NO   | NO         |\n",
      "| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables      | NO           | NO   | NO         |\n",
      "| ARCHIVE            | YES     | Archive storage engine                                         | NO           | NO   | NO         |\n",
      "| InnoDB             | DEFAULT | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES        |\n",
      "| PERFORMANCE_SCHEMA | YES     | Performance Schema                                             | NO           | NO   | NO         |\n",
      "+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+\n"
     ]
    }
   ],
   "source": [
    "mysql_connect \"show engines;\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "既存テーブルのストレージエンジンの確認"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "+--------------+---------------------------+--------+\n",
      "| table_schema | table_name                | engine |\n",
      "+--------------+---------------------------+--------+\n",
      "| mysql        | columns_priv              | MyISAM |\n",
      "| mysql        | db                        | MyISAM |\n",
      "| mysql        | event                     | MyISAM |\n",
      "| mysql        | func                      | MyISAM |\n",
      "| mysql        | general_log               | CSV    |\n",
      "| mysql        | help_category             | MyISAM |\n",
      "| mysql        | help_keyword              | MyISAM |\n",
      "| mysql        | help_relation             | MyISAM |\n",
      "| mysql        | help_topic                | MyISAM |\n",
      "| mysql        | host                      | MyISAM |\n",
      "| mysql        | innodb_index_stats        | InnoDB |\n",
      "| mysql        | innodb_table_stats        | InnoDB |\n",
      "| mysql        | ndb_binlog_index          | MyISAM |\n",
      "| mysql        | plugin                    | MyISAM |\n",
      "| mysql        | proc                      | MyISAM |\n",
      "| mysql        | procs_priv                | MyISAM |\n",
      "| mysql        | proxies_priv              | MyISAM |\n",
      "| mysql        | servers                   | MyISAM |\n",
      "| mysql        | slave_master_info         | InnoDB |\n",
      "| mysql        | slave_relay_log_info      | InnoDB |\n",
      "| mysql        | slave_worker_info         | InnoDB |\n",
      "| mysql        | slow_log                  | CSV    |\n",
      "| mysql        | tables_priv               | MyISAM |\n",
      "| mysql        | time_zone                 | MyISAM |\n",
      "| mysql        | time_zone_leap_second     | MyISAM |\n",
      "| mysql        | time_zone_name            | MyISAM |\n",
      "| mysql        | time_zone_transition      | MyISAM |\n",
      "| mysql        | time_zone_transition_type | MyISAM |\n",
      "| mysql        | user                      | MyISAM |\n",
      "+--------------+---------------------------+--------+\n"
     ]
    }
   ],
   "source": [
    "mysql_connect \"select table_schema, table_name, engine from information_schema.tables where table_schema = 'mysql';\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "# Select"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Bash",
   "language": "bash",
   "name": "bash"
  },
  "language_info": {
   "codemirror_mode": "shell",
   "file_extension": ".sh",
   "mimetype": "text/x-sh",
   "name": "bash"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
